﻿Public Class xtf_ABMconfig_error

    Dim ulg_row As DataRow
    Dim obj_config_error As cls_config_error_ = Nothing

    Public Sub New()
        InitializeComponent()
        CargarImg_()
        AgregarValidaciones()
    End Sub

    Private Sub CargarImg_()
        cargarCombo(cbo_Img, GetType(xtf_ErrManagerAlerta.errManagerImg))
    End Sub

    Public Shadows Sub Nuevo(ByRef listado As Form)
        Try
            frm_listado = listado
            Me.Text = CType(frm_listado, xtf_ListadoBase).lbl_modulo.Text & " - Nuevo"
            obj_config_error = New cls_config_error_
            btn_Registro.Enabled = False
            Me.Show()
        Catch ex As Exception
            'Dim frmError As New frm_ErrorManager(ex.Message)
        End Try
    End Sub

    Public Shadows Sub Modificar(ByRef config_error As cls_config_error_, ByRef listado As Form, ByRef row As DataRow)
        If IsNothing(obj_config_error) Then
            obj_config_error = New cls_config_error_
        End If
        obj_config_error = config_error
        frm_listado = listado
        ulg_row = row : bbi_imprimir.Enabled = True

        Me.Text = CType(frm_listado, xtf_ListadoBase).lbl_modulo.Text & " - " & obj_config_error.ToString
        txt_Codigo.Text = obj_config_error.codigo
        txt_Titulo.Text = obj_config_error.titulo
        txt_Descripcion.Text = Replace(obj_config_error.descripcion, "#", vbNewLine)
        cbo_Img.EditValue = config_error.img

        Me.Show()

    End Sub

    Public Overrides Function ComprobarDatos() As Boolean
        If Not cbo_Img.Enabled Then
            Return False
        End If
        If Not ControlarValidaciones() Then
            ErrManagerShow("000004", Me)
            Return False
        End If
        Return True
    End Function

    Public Shadows Sub btn_Guardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Guardar.Click
        If ComprobarDatos() Then
            obj_config_error.titulo = txt_Titulo.Text
            obj_config_error.descripcion = Replace(txt_Descripcion.Text, vbNewLine, "#")
            obj_config_error.img = cbo_Img.EditValue

            obj_config_error.Modificar()
            If frm_listado.Visible Then
                CType(frm_listado, xtf_LISTADOconfig_error_).ModificarItem(obj_config_error, ulg_row)
            End If
            Modificar(obj_config_error, frm_listado, ulg_row)
            'End If
            flg_Modificado = False : btn_Guardar.Enabled = False : bbi_guardar.Enabled = False
        End If
    End Sub

    Private Sub btn_Registro_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Registro.Click
        'If Not IsNothing(obj_config_error.registro) Then
        '    Dim ABMRegistro As New xtf_ABMRegistro(obj_config_error.registro)
        '    If ABMRegistro.ShowDialog() = Windows.Forms.DialogResult.OK Then
        '        flg_Modificado = True
        '    End If
        'End If
    End Sub


    Private Sub btn_Cerrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Cerrar.Click
        If flg_Modificado Then
            bol_comprobarCerrado = False
            Select Case ErrManagerShow("000001", Me)
                Case Windows.Forms.DialogResult.Yes
                    If ComprobarDatos() Then
                        btn_Guardar_Click(Nothing, Nothing)
                    Else
                        Exit Sub
                    End If
                Case Windows.Forms.DialogResult.Cancel : bol_comprobarCerrado = True
                    Exit Sub
            End Select
        End If
        Me.Dispose()
    End Sub

    Private Sub cbo_Img_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbo_Img.EditValueChanged
        Select Case cbo_Img.EditValue
            Case xtf_ErrManagerAlerta.errManagerImg.img_Error
                pic_img.Image = iml_img.Images(0)
            Case xtf_ErrManagerAlerta.errManagerImg.img_Advertencia
                pic_img.Image = iml_img.Images(1)
            Case xtf_ErrManagerAlerta.errManagerImg.img_Informacion
                pic_img.Image = iml_img.Images(2)
            Case xtf_ErrManagerAlerta.errManagerImg.img_Nula
                pic_img.Image = Nothing
        End Select
    End Sub

    Private Sub btn_ProbarMensaje_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_ProbarMensaje.Click
        ErrManagerShow(txt_Titulo.Text, Replace(txt_Descripcion.Text, vbNewLine, "#"), cbo_Img.EditValue, obj_config_error.botones)
    End Sub
End Class